import {Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy, OnDestroy} from '@angular/core';
import {ToolsService} from "@shared/service/tools/tools.service";
import {ActivatedRoute, Router} from "@angular/router";
import {GoodsService} from "@goods/goods.service";
import {Subject} from "rxjs";

@Component({
  selector: 'seed-goods-faq',
  templateUrl: 'goods-faq.component.html',
  styleUrls: ['goods-faq.component.scss'],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class GoodsFaqComponent implements OnInit, OnDestroy {
  private faqkey: string;
  public ngUnsubscribe: Subject<void> = new Subject<void>();

  constructor(public tools: ToolsService,
              public route: ActivatedRoute,
              public router: Router,
              public goodsService: GoodsService) {
    this.route.queryParams.subscribe(params => {
      const faqkey = params['faqkey'];
      this.getGoodsFaqInfo(faqkey);
    });
  }

   // 获取不同商品的 FAQ 详情信息
  getGoodsFaqInfo(faqkey: string) {
    this.goodsService.getGoodsFaq(faqkey)
      .takeUntil(this.ngUnsubscribe)
      .subscribe(res => {
         // console.log(res);
      });
  }

  ngOnInit() {
  }

  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }

}
